Repository navigation
Tidy up the last few Ruff problems in one_shot.py - #160
Conversation
| """Simple one-shot build flow for non-simulation targets like linting, synthesis and FPV.""" | ||
|
|
||
| ignored_wildcards = [*FlowCfg.ignored_wildcards, "build_mode", "index", "test"] | ||
| ignored_wildcards: ClassVar[list[str]] = [ |
There was a problem hiding this comment.
Aside (you don't need to change it in this PR, it just came to mind as I looked at the code):
It needs a more careful examination, but it looks to me like FlowCfg.ignored_wildcards is only used in its _expand stage (with the HJSON __dict__ replacement magic). That is, I think this class attribute is set once and never mutated (even by the HJSON). If that is the case then this should probably be converted to a ClassVar[tuple[str, ...]] to remove the mutability. Either way the ClassVar type is reasonable here.
There was a problem hiding this comment.
I think that's probably a good idea (and, as you say, probably for a different PR)
e511810 to
5b08ad7
Compare
|
@AlexJones0: Thanks for the review. I've addressed things, but it was a bit more typing than I expected. Accessing the function properly means that Ruff (correctly) points out that we probably shouldn't be calling a private function. All fixed now though, I think. |
machshev
left a comment
There was a problem hiding this comment.
Nice to see the linting being tidied up, thanks @rswarbrick!
Just a nit about the new public method.
| ] | ||
|
|
||
| result = item._gen_results(item_results) | ||
| result = item.gen_results_for_cfg(item_results) |
There was a problem hiding this comment.
I'd leave this private at add a Ruff exclusion to this line. This creates a public method that is only called internally, which I think is worse as we should only create public methods if we plan on supporting the public interface long term. I can't see any reason to, and it makes refactoring more difficult later.
This Ruff rule is to prevent people depending on private methods or attributes of objects they don't own. Which is sensible as if you do this on a third party library it could easily break if the internals are refactored. Here the concern doesn't apply as we have ownership of the method and all it's callers.
While Ruff is technically correct in that it is bad practice and highlights a bigger design issue. I think the real issue is the inheritance model and perhaps the typing of item.
So I'd suggest leaving it private for the moment, add a linting exception to the line and we can refactor later to resolve the underlying issues?
There was a problem hiding this comment.
I think I agree. I've rejigged things and I think it should look better now?
The biggest change is renaming _gen_results to _gen_results_for_cfg. This was originally inspired by me dropping the '_' prefix to avoid what the Ruff tool reports as an external use of a private method. At that point, the names needed de-duplicating. Since this isn't *really* an external use, we've put the underscore back and added a noqa line to explain to Ruff that we've thought about it. But I think the more specific name for the "just this cfg" function is probably a good idea, so I've kept that. Signed-off-by: Rupert Swarbrick <rswarbrick@lowrisc.org>
5b08ad7 to
46af1c6
Compare
No description provided.